A displacement sensor based on principles of triangulation includes a light projecting unit including a light emitting element such as a laser diode and a light receiving unit including such a light receiving element as a PSD, a CCD, and a CMOS, and measures an amount of displacement based on a position in the light receiving unit where reflected light is incident while repeatedly performing processing for emitting light to an object to be detected from the light projecting unit and receiving at the light receiving unit, reflected light from the object to be detected (hereinafter referred to as “detection processing”) and measurement processing for measuring an amount of displacement based on a result of reception of reflected light in a light receiving element.
Additionally, examples of a displacement sensor include a sensor to which a TOF (Time of Flight) method using a length of time from light projection to light reception is applied, a sensor to which a phase difference rangefinding method making use of a phase difference between projected light and received reflected light is applied, a sensor to which a PN code rangefinding method of projecting light of which intensity has been modulated with a PN code so as to conduct measurement using a result of correlation operation between that light and reflected light is applied, and the like.
Among these conventional displacement sensors, in order to stabilize detection, some sensors perform moving average calculation every time measurement data is obtained, by using that data and measurement data for a prescribed number of times in the past, and output an average value obtained in this calculation as detection data (see, for example, PTL 1).
In addition, PTL 1 discloses a displacement sensor having a function to set the number of pieces of data of moving average calculation above to a value suitable for obtaining accuracy demanded by a user through teaching processing by using a model of an object before main processing (see claim 6, paragraphs 0052 to 0057, and FIG. 6 of PTL 1).
Moreover, in order to conduct stable measurement with a displacement sensor, a time period for detection processing should be adjusted. For example, in a displacement sensor of a triangulation type, in order to clarify a peak of a light receiving amount signal generated by a light receiving unit, a light receiving amount signal having sufficient intensity should be obtained, however, intensity of a light receiving amount signal varies depending on a reflectance of a workpiece to be detected. Therefore, in the conventional displacement sensor, light emission intensity of a light emitting element or amplification gain of a light receiving amount signal is adjusted, and in addition, a time period for light projection processing or a time period required for both of light projection and light reception is adjusted in accordance with intensity of a light receiving amount signal (see, for example, paragraph 0021 of PTL 2).